home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / grafica / amhelios / test_1.cpp < prev    next >
C/C++ Source or Header  |  1999-01-01  |  6KB  |  187 lines

  1. ////////////////////////////////////////////////////////////
  2. //
  3. //  TEST_1.CPP - Environment Data File Parser Test Program
  4. //
  5. //  Version:    1.03A
  6. //
  7. //  History:    94/08/23 - Version 1.00A release.
  8. //              94/12/16 - Version 1.01A release.
  9. //              95/02/05 - Version 1.02A release.
  10. //              95/07/21 - Version 1.02B release.
  11. //              96/02/14 - Version 1.02C release.
  12. //              96/04/01 - Version 1.03A release.
  13. //
  14. //  Compilers:  Microsoft Visual C/C++ Professional V1.5
  15. //              Borland C++ Version 4.5
  16. //
  17. //  Author:     Ian Ashdown, P.Eng.
  18. //              byHeart Software Limited
  19. //              620 Ballantree Road
  20. //              West Vancouver, B.C.
  21. //              Canada V7S 1W3
  22. //              Tel. (604) 922-6148
  23. //              Fax. (604) 987-7621
  24. //
  25. //  Copyright 1994-1996 byHeart Software Limited
  26. //
  27. //  The following source code has been derived from:
  28. //
  29. //    Ashdown, I. 1994. Radiosity: A Programmer's
  30. //    Perspective. New York, NY: John Wiley & Sons.
  31. //
  32. //  It may be freely copied, redistributed, and/or modified
  33. //  for personal use ONLY, as long as the copyright notice
  34. //  is included with all source code files.
  35. //
  36. ////////////////////////////////////////////////////////////
  37.  
  38. // NOTE: _NOT_WIN_APP must be globally defined for this
  39. //       program to be successfully compiled
  40.  
  41. #include <stdio.h>
  42. #include <iostream.h>
  43. #include "parse.h"
  44.  
  45. // Default entity directory path
  46. static char NoEntityDir[] = "";
  47.  
  48. static Parse Parser;            // World file parser
  49. static Environ Environment;     // Environment
  50.  
  51. int main( int argc, char **argv )
  52. {
  53.   int inst_num;         // Instance number
  54.   WORD surf_num;        // Surface number
  55.   WORD patch_num;       // Patch number
  56.   WORD elem_num;        // Element number
  57.   WORD vert_num;        // Vertex number
  58.   WORD list_num;        // Polylist number
  59.   char *pentdir;        // Entity directory path
  60.   Instance *pinst;      // Instance pointer
  61.   Surface3 *psurf;      // Surface pointer
  62.   ElemList *pelist;     // Element list pointer
  63.   Patch3 *ppatch;       // Polygon pointer
  64.   Element3 *pelem;      // Element pointer
  65.   Vertex3 *pvert;       // Vertex pointer
  66.   Spectra color;        // Temporary color
  67.   Point3 posn;          // Point co-ordinates
  68.   Vector3 normal;       // Normal vector
  69.  
  70.   // Get entity directory path (if any)
  71.   if (argc > 2)
  72.     pentdir = argv[2];
  73.   else
  74.     pentdir = NoEntityDir;
  75.  
  76.   // Parse the environment file
  77.   if (Parser.ParseFile(argv[1], pentdir, &Environment) ==
  78.       FALSE)
  79.     return 1;
  80.  
  81.   // Get environment pointer
  82.   pinst = Environment.GetInstPtr();
  83.  
  84.   // Walk the instance list
  85.   inst_num = 1;
  86.   while (pinst != NULL)
  87.   {
  88.     cout << "Instance #" << inst_num++ << endl;
  89.  
  90.     // Walk the surface list
  91.     surf_num = 1;
  92.     psurf = pinst->GetSurfPtr();
  93.     while (psurf != NULL)
  94.     {
  95.       cout << "  Surface #" << surf_num++ << endl;
  96.       color = psurf->GetReflectance();
  97.       cout << "    reflectance = [ " << color.GetRedBand()
  98.           << " " << color.GetGreenBand() << " " << 
  99.           color.GetBlueBand() << " ]" << endl;
  100.       color = psurf->GetEmittance();
  101.       cout << "    emittance = [ " << color.GetRedBand() <<
  102.           " " << color.GetGreenBand() << " " << 
  103.           color.GetBlueBand() << " ]" << endl;
  104.  
  105.       // Walk the patch list
  106.       patch_num = 1;
  107.       ppatch = psurf->GetPatchPtr();
  108.       while (ppatch != NULL)
  109.       {
  110.         cout << "    Patch #" << patch_num++ << endl;
  111.         cout << "      area = " << ppatch->GetArea() <<
  112.             endl;
  113.         posn = ppatch->GetCenter();
  114.         cout << "      center = < " << posn.GetX() << " "
  115.             << posn.GetY() << " " << posn.GetZ() << " >" <<
  116.             endl;
  117.         normal = ppatch->GetNormal();
  118.         cout << "      normal = < " << normal.GetX() << " "
  119.             << normal.GetY() << " " << normal.GetZ() <<
  120.             " >" << endl;
  121.         color = ppatch->GetExitance();
  122.         cout << "      exitance = [ " << color.GetRedBand()
  123.             << " " << color.GetGreenBand() << " " << 
  124.             color.GetBlueBand() << " ]" << endl;
  125.  
  126.         // Walk the patch element list
  127.         elem_num = 1;
  128.         pelem = ppatch->GetElementPtr();
  129.         while (pelem != NULL)
  130.         {
  131.           cout << "      Element #" << elem_num++ << endl;
  132.           cout << "        area = " << pelem->GetArea() <<
  133.               endl;
  134.           normal = pelem->GetNormal();
  135.           cout << "        normal = < " << normal.GetX() <<
  136.               " " << normal.GetY() << " " << normal.GetZ()
  137.               << " >" << endl;
  138.           color = pelem->GetExitance();
  139.           cout << "        exitance = [ " <<
  140.               color.GetRedBand() << " " <<
  141.               color.GetGreenBand() << " " << 
  142.               color.GetBlueBand() << " ]" << endl;
  143.  
  144.           pelem = pelem->GetNext();
  145.         }
  146.         ppatch = ppatch->GetNext();
  147.       }
  148.       psurf = psurf->GetNext();
  149.     }
  150.  
  151.     // Walk the vertex list
  152.     vert_num = 1;
  153.     pvert = pinst->GetVertPtr();
  154.     while (pvert != NULL)
  155.     {
  156.       cout << "  Vertex #" << vert_num++ << endl;
  157.       posn = pvert->GetPosn();
  158.       cout << "    position = < " << posn.GetX() << " " <<
  159.           posn.GetY() << " " << posn.GetZ() << " >" << endl;
  160.       normal = pvert->GetNormal();
  161.       cout << "    normal = < " << normal.GetX() << " " <<
  162.           normal.GetY() << " " << normal.GetZ() << " >" <<
  163.           endl;
  164.       color = pvert->GetExitance();
  165.       cout << "    color = [ " <<  color.GetRedBand() << " "
  166.           << color.GetGreenBand() << " " <<
  167.           color.GetBlueBand() << " ]" << endl;
  168.  
  169.       // Walk the vertex element list
  170.       list_num = 0;
  171.       pelist = pvert->GetElemListPtr();
  172.       while (pelist != NULL)
  173.       {
  174.         list_num++;
  175.         pelist = pelist->GetNext();
  176.       }
  177.       cout << "    vertex shared by " << list_num <<
  178.           " elements" << endl;
  179.       pvert = pvert->GetNext();
  180.     }
  181.     pinst = pinst->GetNext();
  182.   }
  183.  
  184.   return 0;
  185. }
  186.  
  187.